home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2001 December / pcwk12201b.iso / Wersje pelne i specjalne / Winamp 2.77 i 3.0beta / wasabi-sdk_beta1.exe / studio / common / transcendentals.cpp < prev    next >
C/C++ Source or Header  |  2001-10-08  |  3KB  |  106 lines

  1. /*
  2.  
  3.   Nullsoft WASABI Source File License
  4.  
  5.   Copyright 1999-2001 Nullsoft, Inc.
  6.  
  7.     This software is provided 'as-is', without any express or implied
  8.     warranty.  In no event will the authors be held liable for any damages
  9.     arising from the use of this software.
  10.  
  11.     Permission is granted to anyone to use this software for any purpose,
  12.     including commercial applications, and to alter it and redistribute it
  13.     freely, subject to the following restrictions:
  14.  
  15.     1. The origin of this software must not be misrepresented; you must not
  16.        claim that you wrote the original software. If you use this software
  17.        in a product, an acknowledgment in the product documentation would be
  18.        appreciated but is not required.
  19.     2. Altered source versions must be plainly marked as such, and must not be
  20.        misrepresented as being the original software.
  21.     3. This notice may not be removed or altered from any source distribution.
  22.  
  23.  
  24.   Brennan Underwood
  25.   brennan@nullsoft.com
  26.  
  27. */
  28.  
  29. #include "transcendentals.h"
  30.  
  31. #include "std.h"
  32.  
  33. int        Transcendental::currentTableBitdepth = 0;
  34.  
  35. // All the tables.
  36. Real *    Transcendental::sinTable = (Real *)NULL;
  37.  
  38.  
  39. //
  40. //    Constructors and Destructors
  41. Transcendental::Transcendental() {
  42.     initializeBitdepth( DEFAULT_TABLE_BITDEPTH );
  43. }
  44.  
  45. Transcendental::~Transcendental() {
  46.     //
  47.     // Delete all the allocated tables.
  48.     deleteTable( sinTable );
  49.  
  50. }
  51.  
  52. void        Transcendental::initializeBitdepth( const int newBitdepth ) {
  53.     //
  54.     //    For now, we'll call "SetBitdepth" -- soon we will save the default as a header table.
  55.     setBitdepth( newBitdepth );
  56. }
  57.  
  58. void        Transcendental::setBitdepth( const int newBitdepth ) {
  59.     if ( newBitdepth >= 1 && newBitdepth <= 32 && newBitdepth != currentTableBitdepth ) {
  60.         // Set the variable
  61.         currentTableBitdepth = newBitdepth;
  62.  
  63.         // And regenerate all the tables
  64.         makeTable( sinTable );
  65.     }
  66. }
  67.  
  68. int            Transcendental::getBitdepth( void ) {
  69.     return currentTableBitdepth;
  70. }
  71.  
  72.  
  73.  
  74. Real        Transcendental::mCRTSin( const Real radians ) {
  75.     return SIN( radians );
  76. }
  77.  
  78. Real        Transcendental::mCRTCos( const Real radians ) {
  79.     return COS( radians );
  80. }
  81.  
  82. void        Transcendental::makeTable( Real *&theTable ) {
  83.     deleteTable( theTable );
  84.  
  85.     if ( sinTable == NULL )
  86.     {
  87.         int numTableEntries = 1 << currentTableBitdepth; 
  88.         sinTable = new Real[ numTableEntries ];
  89.         if ( sinTable != NULL )
  90.         {
  91.             int i;
  92.             Real radians = 0,step = ((Real)1)/((Real)numTableEntries);
  93.             for ( i = 0; i < numTableEntries; i++, radians += step )
  94.             {
  95.                 sinTable[i] = mCRTSin( radians );
  96.             }
  97.         }
  98.  
  99.     }
  100. }
  101.  
  102. void        Transcendental::deleteTable( Real *&theTable ) {
  103. }
  104.  
  105.  
  106.